<?php
// Tampon qui intercepte tous les outputs jusqu'à ob_end_flush (automatique), en zippant le contenu si possible
if(substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start('ob_gzhandler');
else ob_start();

session_start();

require_once('lib/utils.php');
require_once('lib/mysql.php');
require_once('lib/constants.php');
require_once('lib/member.php');

date_default_timezone_set(TIMEZONE);

sql_connect();

if (!isset($_SESSION['is_connect'])) {
	$_SESSION['is_connect'] = false;
}

if (!$_SESSION['is_connect'] && !isset($_GET['deconnexion'])) {
	// connexion depuis un cookie
	if (isset($_COOKIE['adr-login']) && isset($_COOKIE['adr-password'])) {
		$email = clean_str($_COOKIE['adr-login']);
		$password = clean_str($_COOKIE['adr-password']);
		member_connect($email, $password);
	}
}

// retour à l'index si l'accès est refusé ou si demande de déconnexion
if (!$_SESSION['is_connect'] || ($_SESSION['status_code'] != 'ADMIN' && $_SESSION['status_code'] != 'MODERATOR') || isset($_GET['deconnexion'])) {
	unset($_SESSION);
	session_destroy();
	header('location: accueil.html');
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Adrénaline Administration</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="author" content="Alexandre Bodelot, Julien Paroche" />

	<!-- indiquer aux moteurs de recherche que cette partie n'est pas à indexer -->
	<meta name="robots" content="noindex, nofollow" />

	<!-- css -->
	<link rel="stylesheet" media="screen" type="text/css" href="design/commun.css" />
	<link rel="stylesheet" media="screen" type="text/css" href="design/jquery.css" />
	<link rel="stylesheet" media="screen" type="text/css" href="design/admin/admin.css" />
	<link rel="stylesheet" media="screen" type="text/css" href="design/admin/datatables.css" />

	<!--[if lte IE 8]>
	<link rel="stylesheet" media="screen" type="text/css" href="design/ie.css"  />
	<![endif]-->

	<!-- jquery libs - web -->
	<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js" type="text/javascript"></script>-->

	<!-- jquery libs - loc -->
	<script src="javascript/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
	<script src="javascript/jquery/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
	<script src="javascript/jquery/jquery.numeric.pack.js" type="text/javascript"></script>
	<script src="javascript/jquery/jquery.dataTables.min.js" type="text/javascript"></script>
	<script src="javascript/jquery/jquery.confirm-1.3.js" type="text/javascript"></script>
	<script src="javascript/jquery/jquery.flot.min.js" type="text/javascript"></script>

	<script src="javascript/utils.js" type="text/javascript"></script>
	<script src="javascript/admin_common.js" type="text/javascript"></script>

	<!-- website mini-icon -->
	<link rel="icon" href="images/icons/cog.png" type="image/png" />
</head>

<body>
	<div id="wrapper">
    	<!-- h1 tag stays for the logo, you can use the a tag for linking the index page -->
    	<h1><a href="accueil.html"><span>Adrénaline website</span></a></h1>

		<?php include_once('includes/admin_menu_top.php'); ?>
        <!-- // #end mainNav -->

        <div id="containerHolder">
			<div id="container">
        		<div id="sidebar">
					<?php include_once('includes/admin_menu_left.php'); ?>
                    <!-- // .sideNav -->
                </div>
                <!-- // #sidebar -->

                <div id="main">
					<?php
					$path = remove_updir('pages_admin/'.$page.'/'.$rubrique.'.php');
					if ($page == 'menus' && $_SESSION['status_code'] != 'ADMIN') {
						?>
						<h3>Erreur</h3>
						<p class="error">Vous n'avez pas accès à cette section</p>
						<?php
					}
					elseif (file_exists($path)) {
						require_once($path);
					}
					else {
						?>
						<h3>Erreur</h3>
						<p class="error">La page demandée n'existe pas</p>
						<?php
					}
					?>
                </div>
                <!-- // #main -->

                <div class="clear"></div>
            </div>
            <!-- // #container -->
        </div>
        <!-- // #containerHolder -->

        <?php include_once('includes/admin_footer.php'); ?>
    </div>
    <!-- // #wrapper -->
</body>
</html>
